#include <iostream>
#include "../src/onvif_server.h"

using namespace El::Onvif;

int main() {
    std::cout << "ONVIF Server Test" << std::endl;
    
    try {
        // 创建ONVIF服务器
        OnvifServer server(8080);
        
        // 设置设备信息
        DeviceInformation deviceInfo;
        deviceInfo.manufacturer = "Test Manufacturer";
        deviceInfo.model = "Test Camera";
        deviceInfo.firmwareVersion = "1.0.0";
        deviceInfo.serialNumber = "12345678";
        deviceInfo.hardwareId = "HW-TEST-001";
        server.SetDeviceInformation(deviceInfo);
        
        // 设置网络配置
        NetworkInterface networkConfig;
        networkConfig.token = "eth0";
        networkConfig.enabled = true;
        networkConfig.ipAddress = "192.168.1.100";
        networkConfig.prefixLength = 24;
        networkConfig.gateway = "192.168.1.1";
        networkConfig.dns = {"8.8.8.8", "8.8.4.4"};
        server.SetNetworkConfiguration(networkConfig);
        
        // 添加用户
        User admin;
        admin.username = "admin";
        admin.password = "admin123";
        admin.userLevel = User::UserLevel::ADMINISTRATOR;
        server.AddUser(admin);
        
        // 添加媒体配置文件
        MediaProfile profile;
        profile.token = "Profile_1";
        profile.name = "Main Profile";
        profile.fixed = true;
        profile.videoSourceToken = "VideoSource_1";
        profile.videoEncoderToken = "VideoEncoder_1";
        profile.streamUris.rtspUri = "rtsp://192.168.1.100:554/stream1";
        server.AddMediaProfile(profile);
        
        std::cout << "Server configuration completed." << std::endl;
        
        // 启动服务器
        if (server.Start()) {
            std::cout << "ONVIF Server started successfully on port 8080" << std::endl;
            std::cout << "Press Enter to stop the server..." << std::endl;
            std::cin.get();
            
            server.Stop();
            std::cout << "ONVIF Server stopped." << std::endl;
        } else {
            std::cerr << "Failed to start ONVIF Server!" << std::endl;
            return 1;
        }
        
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
    
    return 0;
}